//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_SCENE_IMPORT_VRML_ZTOKEN_H_
#define _BUOLA_SCENE_IMPORT_VRML_ZTOKEN_H_

#include <buola/zz/zbase.h>

#include "enums.h"
#include "ctoken.h"

namespace buola { namespace scene { namespace vrml {

template<bool vHasAttr>
struct ZToken : public zz::ZBase<ZToken<vHasAttr>>
{
    // Define the attribute type exposed by this parser component
    template<typename tIt>
    struct tAttribute
    {
        typedef typename std::conditional<vHasAttr,CToken,UUnused>::type tType;
    };

    ZToken(EToken pToken)
        :   mToken(pToken)
    {}
    
    ZToken(const ZToken &pToken)
        :   mToken(pToken.mToken)
    {}
    
    ZToken(ZToken &&pToken)
        :   mToken(pToken.mToken)
    {}
    
    // This function is called during the actual parsing process
    template <typename tIt,typename tAttr,typename tCtx,typename tSk>
    bool Parse(tIt &pB,const tIt &pE,tAttr &pAttr,tCtx&,const tSk &pSk) const
    {
//        msg_info() << "ddd " << (int)mToken << "\n";
        zz::skip_over(pB,pE,pSk);
        
        if(pB==pE) 
            return false;

        if(pB->mToken==mToken)
        {
            pAttr=*pB;
            ++pB;
            return true;
        }
        return false;
    }
    
    EToken mToken;
};

inline ZToken<false> ztoken(EToken pToken)
{
    return ZToken<false>(pToken);
}

inline ZToken<true> zattrtoken(EToken pToken)
{
    return ZToken<true>(pToken);
}
    
/*namespace vrml*/ } /*namespace scene*/ } /*namespace buola*/ }

#endif
